﻿@model ConferenceCheckInModel
@{
	ViewBag.Title = Resources.ConferenceCheckIn + ConstValues.strDash + ViewBag.ConferenceName;
}
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@Resources.HotelName：<input id="selHotelName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		@Resources.RoomType：<input id="selRoomType" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		@Resources.IsCombine：<select class="easyui-combobox" id="selIsCombine" style="height:27px; width:200px;" data-options="editable:false,panelHeight:'auto'">
			<option value="">@Resources.All</option>
			<option value="@ConstValues.GenericSelectionType.有">@Resources.Yes</option>
			<option value="@ConstValues.GenericSelectionType.无">@Resources.No</option>
		</select>&nbsp;&nbsp;
		@Resources.Status： <select class="easyui-combobox" id="selStatus" style="height:27px; width:200px;" data-options="editable:false,panelHeight:'auto'">
			<option value="">@Resources.All</option>
			<option value="@ConstValues.Status.已预订">@Resources.HasBooked</option>
			<option value="@ConstValues.Status.已取消">@Resources.ScheduleStatusCancel</option>
		</select>&nbsp;&nbsp;
		@Resources.FullName：<input id="selFullName" class="easyui-textbox" style="height:27px; width:200px;" />&nbsp;&nbsp;
		<a onclick="searchData()" class="easyui-linkbutton" iconcls="icon-search">@Resources.Search</a>
	</div>
	<div class="clear"></div>
</div>
<div id="menuBar" style="height:35px;">
	<div style="float: left; padding: 5px 5px; font-weight: bold; text-align: left;">
		@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceCheckIn, RoleType.添加))
		{
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-download" onclick="downloadImportTemplate();" plain="true">@Resources.TemplateDownLoad</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-import" onclick="openImport();" plain="true">@Resources.Import</a>
		}
		<a href="javascript:void(0);" id="export" class="easyui-linkbutton" iconcls="icon-export" onclick="exportData();" plain="true">@Resources.Export</a>
	</div>
	<form id="frmExport" method="post" target="iframeDownload" action="@Url.Action(nameof(ConferenceCheckInController.Export))">
		@Html.AntiForgeryToken()
		<input type="hidden" id="hdnIds" name="allId" />
		<input type="hidden" id="hidConferenceId" name="conferenceId" />
	</form>
	<iframe id="iframeDownload" style="width:0; height:0; visibility:hidden" tabindex="-1"></iframe>
	<div class="clear"></div>
</div>
<div id="dataGrid"></div>

@section bodyParts {
<div id="importWindow" class="easyui-window"
	title="@Resources.Import @Resources.ConferenceCheckIn" data-options="closed:true,minimizable:false,iconCls:'icon-save'"
	style="width:600px; display:none;">
	<div class="popupDiv">
		<form id="frmImport" method="post" enctype="multipart/form-data">
			@Html.AntiForgeryToken()
			<input id="hidIptConferenceId" name="ConferenceId" type="hidden" />
			<input id="importFile" name="ImportFile" class="easyui-filebox" style="height:27px; width:500px;" data-options="required:true, prompt:'@Resources.Import', buttonText:'@Resources.ChooseFile', accept:'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'" />
		</form>
		<div class="buttonDiv">
			<input type="button" class="btn lbtn" onclick="importData();" value="@Resources.Import" />&nbsp;&nbsp;
			<input type="button" class="btn rbtn" onclick="$('#importWindow').window('close');" value="@Resources.Cancel" />
		</div>
	</div>
</div>
<div id="hotelBookingWindow" class="easyui-window"
	title="@Resources.Create" data-options="closed:true,minimizable:false,maximizable:false,iconCls:'icon-save'"
	style="width:1200px; display:none;">
	<div class="main">
		<div class="box clearfix">
			<form id="hotelForm">
				@Html.AntiForgeryToken()
				<table class="booking" id="booking">
					<tr>
						<td style="width:35%;text-align:right">@Resources.HotelName：</td>
						<td><input id="hotel" name="hotel" class="easyui-combobox" style="height:27px; width:500px;" data-options="required:true"></td>
					</tr>
					<tr>
						<td>@Resources.RoomType：</td>
						<td>
							<input id="roomType" name="roomType" class="easyui-combobox" style="height:27px; width:150px;" data-options="required:true">
							<span style="margin-left:20px">@Resources.Price：</span>
							<span style="margin-left:20px" id="roomPrice"></span>
							<input type="hidden" id="hidPrice">
						</td>
					</tr>
					<tr>
						<td>@Resources.CheckinDate：</td>
						<td>
							<input id="checkinDate" name="checkinDate" class="easyui-combobox" style="height:27px; width:150px;" data-options="editable:false,required:true">
							<span style="margin-left:20px">@Resources.CheckoutDate：</span>
							<input id="checkoutDate" name="checkoutDate" class="easyui-combobox" style="height:27px; width:150px;" data-options="editable:false,required:true">
							<span style="margin-left:20px;width:60px;display: inline-block" id="totalNightCount"></span>
							<span style="margin-left:20px">@Resources.RoomNumber：</span>
							<input id="roomNumber" name="roomNumber" class="easyui-numberbox" style="height:27px; width:50px;" data-options="required:true,min:0,precision:0">
						</td>
					</tr>
					<tr id="tips" style="display:none">
						<td colspan="2">
							<div id="tipsDiv">
								<table style="border:#CEDDEF solid 1px; width:800px ;max-width:800px; margin-left:190px">
									<tr>
										<td align="center" style="width:15%;text-align:center">@Resources.RoomType</td>
										<td align="center" style="width:15%;text-align:center">@Resources.LeftRoomCount</td>
										<td align="center" style="width:65%;text-align:center">@Resources.ScheduleDate</td>
									</tr>
									<tr style="height:2px;">
										<td align="center" colspan="3" style="padding:0px;line-height:1px;margin:0;"><div style="width:95%;height:1px;background:#C4C3C3;line-height:1px;padding:0;margin-left:15px;"></div></td>
									</tr>
									<tr class="booking-line">
										<td align="center" style="width:15%;text-align:center"><span id="leftRoomName"></span></td>
										<td align="center" style="width:15%;text-align:center"><span id="leftRoomCount"></span></td>
										<td align="center" style="width:65%"><div id="leftRoomDetail"></div></td>
									</tr>
									<tr style="height:2px;">
										<td align="center" colspan="3" style="padding:0px;line-height:1px;margin:0;"><div style="width:95%;height:1px;background:#C4C3C3;line-height:1px;padding:0;margin-left:15px;"></div></td>
									</tr>
									<tr>
										<td align="center" style="text-align:left;padding-left: 20px;" colspan="3">@Resources.KindlyReminder</td>
									</tr>
								</table>
							</div>
						</td>
					</tr>
					<tr>
						<td>@Resources.CheckInNumber：</td>
						<td><input id="checkInNumber" name="checkInNumber" class="easyui-numberbox" style="height:27px; width:50px;" data-options="required:true,min:0,precision:0"></td>
					</tr>
					<tr>
						<td valign="top">@Resources.CheckInName：</td>
						<td valign="top"><span id="nameTd"></span></td>
					</tr>
					<tr>
						<td><span>@Resources.Contact：</span></td>
						<td>
							<input id="contactName" name="contactName" class="easyui-textbox" style="height:27px; width:150px;" data-options="required:true">
							<span style="margin-left:10px;display:inline-block; width:60px;">@Resources.Mobile：</span><input id="contactMobile" name="contactMobile" class="easyui-numberbox" style="height:27px; width:150px;" data-options="required:true,min:0,precision:0">
							<span style="margin-left:10px;display:inline-block; width:60px;">@Resources.Mail：</span><input id="contactMail" name="contactMail" class="easyui-textbox" style="height:27px; width:150px;" data-options="required:true,validType:['email','length[1,100]']">
						</td>
					</tr>
					<tr>
						<td><span>@Resources.Remark：</span></td>
						<td>
							<input id="hotelRemark" name="hotelRemark" class="easyui-textbox" style="height:50px; width:616px;" data-options="multiline:true,validType:['length[1,1000]']">
						</td>
					</tr>
				</table>
				<input type="hidden" id="hidCurrency" />
				<input type="hidden" id="hdnSubmitType">
				<input type="hidden" id="profileHotelId" name="profileHotelId">
				<input type="hidden" id="hidConferenceId2" name="conferenceId" />
				<input type="hidden" id="hidOrderNumber" />
			</form>
			<div class="clear"></div>
			<div style="padding: 25px 0; text-align: center;">
				<input type="button" class="gbtn" onclick="doHotelBooking();" value="@Resources.Save" />
				<input type="button" class="rbtn" onclick="$('#hotelBookingWindow').window('close');" value="@Resources.Cancel" />
			</div>
		</div>
	</div>
</div>
}

@section Scripts {
<script>
	common.setCurrentMenu("ConferenceCheckIn");
	common.setCurrentParentMenu("#menu_a4");

	$(function () {
		$("#hidConferenceId").val("@Model.ConferenceId");
		$("#hidConferenceId2").val("@Model.ConferenceId");
		$("#tt").tabs({
			width: $(window).width() - 265,
		});

		$("#selHotelName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		});
		$("#selRoomType").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		})
		$("#selIsCombine").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		})
		$("#selFullName").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		})
		$("#selStatus").textbox("textbox").bind("keydown", function (e) {
			if (e.keyCode == 13) {
				searchData()
			}
		})

		$("#dataGrid").datagrid({
			url: "@Url.Action(nameof(ConferenceCheckInController.GetData),
			nameof(ConferenceCheckInController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
			method: "get",
			checkOnSelect: false,
			width: $(window).width() - 285,
			height: $(window).height() - 158 - 38,
			nowrap: false,
			pagination: true,
			pageSize: @ConstValues.DefaultGridRows,
			striped: true,
			toolbar: "#toolBar",
			pageSize: 100,
			pageList: [100, 200, 300, 400, 500],
			rowStyler: function(index, row) {
				if (row.status == "@ConstValues.Status.已取消") {
					return "background-color:#CCCCCC;";
				}
			},
			columns: [[
				{ field: "chk", align: "center", checkbox: true },
				{ field: "id", hidden: true },
				@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) ||
			Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceCheckIn, RoleType.修改) ||
			Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceCheckIn, RoleType.删除))
		{
			<text>
					{
						field: "operate", title: "@Resources.Operate", align: "center", width: 200,
						formatter: function(value, rec) {
							var strInfo = "";
							if (rec.status == "@ConstValues.ScheduleStatus.已取消") {
								@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceCheckIn, RoleType.删除))
						{
							<text>
								if (strInfo != "") {
									strInfo += "&nbsp;|&nbsp;";
								}
								strInfo += "<a href='#' style='color:#000000;font-weight:bold;text-decoration:underline;' onclick='bookingData(\""
									+ rec.id + "\")'>@Resources.ScheduleRecover</a>";
								</text>
						}
							} else {
								@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceCheckIn, RoleType.修改))
						{
							<text>
								strInfo = "<a href='#' style='color:#66CDAA;font-weight:bold;text-decoration:underline;' onclick='hotelDetailModify(\""
									+ rec.id + "\",\""+ rec.currency + "\",\""+ rec.orderNum + "\")'>@Resources.Modify</a>";
								</text>
						}
								@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceCheckIn, RoleType.删除))
						{
							<text>
								if (strInfo != "") {
									strInfo += "&nbsp;|&nbsp;";
								}
								strInfo += "<a href='#' style='color:#DC143C;font-weight:bold;text-decoration:underline;' onclick='cancelData(\""
									+ rec.id + "\")'>@Resources.Cancel</a>";
								</text>
						}
							}

							@if ((User as ICISPrincipal).IsSSA || (User as ICISPrincipal).CSAList.Contains(Model.ConferenceId) || Utility.HasConferenceRole((User as ICISPrincipal), Model.ConferenceId, ConstValues.FunctionId.ConferenceCheckIn, RoleType.删除))
					{
						<text>
							if (strInfo != "") {
								strInfo += "&nbsp;|&nbsp;";
							}
							strInfo += "<a href='#' style='color:#FF8C00;font-weight:bold;text-decoration:underline;' onclick='deleteData(\""
								+ rec.id + "\")'>@Resources.Delete</a>";
							</text>
					}

							return strInfo;
						}
					},
					</text>
		}
				{
					field: "status", title: "@Resources.Status", align: "center", sortable: true, width: 100,
					formatter: function(value, rec) {
						if (value=="@ConstValues.Status.已预订") {
							return "@Resources.HasBooked";
						} else {
							return "@Resources.ScheduleStatusCancel";
						}
					}
				},
				{ field: "orderNum", title: "@Resources.OrderNum", align: "center", sortable: true, width: 200 },
				{ field: "dummyRoomNum", title: "@Resources.DummyRoomNum", align: "center", sortable: true, width: 100 },
				{ field: "hotelName", title: "@Resources.HotelName", align: "center", sortable: true, width: 200 },
				{ field: "roomType", title: "@Resources.RoomType", align: "center", sortable: true, width: 150 },
				{
					field: "isCombine", title: "@Resources.IsCombine", align: "center", sortable: true, width: 150,
					formatter: function (value, rec) {
						if (value == true) {
							return "@Resources.Yes";
						} else if (value == false) {
							return "@Resources.No";
						} else {
							return "";
						}
					}
				},
				{ field: "name1", title: "@Resources.FullName 1", align: "center", sortable: true, width: 150 },
				{ field: "name2", title: "@Resources.FullName 2", align: "center", sortable: true, width: 150 },
				{ field: "checkinDate", title: "@Resources.CheckinDate", align: "center", sortable: true, width: 150 },
				{ field: "checkoutDate", title: "@Resources.CheckoutDate", align: "center", sortable: true, width: 150 },
				{ field: "currency", title: "@Resources.Currency", align: "center", sortable: true, width: 100 },
				{ field: "price", title: "@Resources.Fee", align: "center", width: 100 },
				{ field: "remark", title: "@Resources.Remark", align: "center", sortable: true, width: 200 },
				{ field: "contact", title: "@Resources.Contact", align: "center", sortable: true, width: 150 },
				{ field: "contactPhone", title: "@Resources.ContactPhone", align: "center", sortable: true, width: 150 },
				{ field: "contactMail", title: "@Resources.ContactMail", align: "center", sortable: true, width: 200 },
				{ field: "creator", title: "@Resources.Creator", align: "center", sortable: true, width: 150 },
				{ field: "createDate", title: "@Resources.CreateDate", align: "center", sortable: true, width: 150 },
			]],
			onBeforeLoad: function(param) {
				param.random = Math.random();
				param.conferenceId = $("#hidConferenceId").val();
			},
			onLoadSuccess: function(data) {
				var exportIdList = $("#hdnIds").val();
				if (data.rows.length > 0) {
					var exportIdArray = exportIdList.split(',');
					for (var rowIndex = 0; rowIndex < data.rows.length; rowIndex++) {
						for (var index = 0; index < exportIdArray.length; index++) {
							if (data.rows[rowIndex].dummyRoomNum == exportIdArray[index]) {
								$("input[type='checkbox']").eq(rowIndex + 1).prop("checked", true);
								break;
							}
						}
					}
				}
			},
			onCheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var strId = rowData.dummyRoomNum.toString();
				if (exportIdList == "") {
					$("#hdnIds").val(strId);
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray.concat(strId);
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheck: function (rowIndex, rowData) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				var strId = rowData.dummyRoomNum.toString();
				exportIdArray.remove(strId);
				$("#hdnIds").val(exportIdArray.join());
			},
			onCheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				if (exportIdList == "") {
					var newArray = new Array();
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].dummyRoomNum.toString();
						newArray = newArray.concat(strId);
					}
					$("#hdnIds").val(newArray.join());
				} else {
					var exportIdArray = exportIdList.split(',');
					var newArray = exportIdArray;
					for (var index = 0; index < rows.length; index++) {
						var strId = rows[index].dummyRoomNum.toString();
						if (newArray.indexOf(strId) < 0) {
							newArray = newArray.concat(strId);
						}
					}
					$("#hdnIds").val(newArray.join());
				}
			},
			onUncheckAll: function (rows) {
				var exportIdList = $("#hdnIds").val();
				var exportIdArray = exportIdList.split(',');
				for (var index = 0; index < rows.length; index++) {
					var strId = rows[index].dummyRoomNum.toString();
					exportIdArray.remove(strId);
				}
				$("#hdnIds").val(exportIdArray.join());
			},
		});

		$(window).resize(function () {
			$("#dataGrid").datagrid("resize", {
				width: $(window).width() - 285,
				height: $(window).height() - 158 - 38
			});
		});

		$("#importWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: ($(window).height() - 600) * 0.5
		});

		$("#hotelBookingWindow").window({
			onOpen: function () {
				$(this).scrollTop(0);
			},
			top: 100
		});
	});

	function searchData() {
		$("#hdnIds").val("");
		$("#dataGrid").datagrid("load", {
			SelHotelName: $("#selHotelName").textbox("getValue"),
			SelRoomType: $("#selRoomType").textbox("getValue"),
			SelIsCombine: $("#selIsCombine").combobox("getValue"),
			SelFullName: $("#selFullName").textbox("getValue"),
			SelStatus: $("#selStatus").combobox("getValue"),
		});
	}

	function exportData(){
		var exportIdList = $("#hdnIds").val();

		if (exportIdList == "") {
			$.messager.alert("@Resources.Export", "@Resources.MsgRecordMust", "warning");
			return;
		}
		$("#frmExport").submit();
	}

	function downloadImportTemplate() {
		var url = "@Url.Action(nameof(ConferenceCheckInController.DownloadImportTemplate),
		nameof(ConferenceCheckInController).GetControllerName())";
		$("#iframeDownload").attr("src", url);
	}

	function openImport() {
		$("#importFile").filebox("clear")
		$("#importWindow").window("open");
	}

	function importData() {
		var loading = layer.load(0,  {
			shade: [0.4,"#fff"]
		});

		$("#hidIptConferenceId").val("@Model.ConferenceId");

		$("#frmImport").form({
			iframe: false,
			success: function (data) { }
		});

		$("#frmImport").form("submit", {
			url: "@Url.Action(nameof(ConferenceCheckInController.Import), nameof(ConferenceCheckInController).GetControllerName(),
					new { ConferenceId = Model.ConferenceId })",
			onSubmit: function (param) {
				param.random = Math.random();
			},
			success: function (data) {
				layer.close(loading);
				data = JSON.parse(data);
				if (data.result == "@ConstValues.AjaxFailResult") {
					common.showError(data.message);
					$("#dataGrid").datagrid("reload");
				} else {
					common.showSuccess(data.message, true);
					$("#importWindow").window("close");
					$("#dataGrid").datagrid("reload");
				}
			}
		});
	}

	function hotelDetailModify(id, currency, orderNum) {
		var loading = layer.load(0, {
			shade: [0.4, "#fff"]
		});
		$("#hdnSubmitType").val("edit");
		$("#profileHotelId").val(id);
		$("#hidCurrency").val(currency);
		$("#hidOrderNumber").val(orderNum);

		var url = "@Url.Action(nameof(ProfileHotelController.GetHotelDetail),
				nameof(ProfileHotelController).GetControllerName())" + "?id=" + id;
		$.post(url, $("#hotelForm").serialize(), function (data, textStatus, jqXHR) {
			if (data.result == "@ConstValues.AjaxFailResult") {
				common.showError(data.message);
			} else {
				$("#roomType").combobox("loadData", {});
				$("#roomNumber").numberbox("clear");
				$("#checkInNumber").numberbox("clear");
				$("span[id='totalNightCount']").html("")
				$("span[id='roomPrice']").html("");
				$("#nameTd").empty();
				$("#hotel").combobox({
					url: "@Url.Action(nameof(UtilityController.GetHotel),
					nameof(UtilityController).GetControllerName())?conferenceId=" + data.data.conferenceId,
					valueField: "id",
					textField: "name",
					required: true,
					editable: false,
					panelHeight: "auto",
					onChange: function (rec) {
						$("span[id='roomPrice']").html("");
						document.getElementById("tips").style.display = "none";
						$("#roomType").combobox({
							url: "@Url.Action(nameof(UtilityController.GetDistinctRoom),
							nameof(UtilityController).GetControllerName())?hotelId=" + rec + "&currency=" + data.data.currency,
							valueField: "id",
							textField: "name",
							editable: false,
							panelHeight: "auto",
							onSelect: function (record) {
								if ($("#hidIsBenefit").val() == "True") {
									$("span[id='roomPrice']").html(record.currency + " " + record.price2);
									$("#hidPrice").val(record.price2)
								} else {
									$("span[id='roomPrice']").html(record.currency + " " + record.price1);
								}
								getHotelTips();
							}
						});
					}
				});
				$("#checkinDate").combobox({
					url: "@Url.Action(nameof(UtilityController.GetConferenceCheckinDate),
					nameof(UtilityController).GetControllerName())" + "?conferenceId=" +data.data.conferenceId,
					valueField: "id",
					textField: "id",
					required: true,
					editable: false,
					panelHeight: "auto",
					onSelect: function (rec) {
						getHotelTips();
						calculateNight();
						compareDate();
					}
				});
				$("#checkoutDate").combobox({
					url: "@Url.Action(nameof(UtilityController.GetConferenceCheckinDate),
					nameof(UtilityController).GetControllerName())" + "?conferenceId=" + data.data.conferenceId,
					valueField: "id",
					textField: "id",
					required: true,
					editable: false,
					panelHeight: "auto",
					onSelect: function (rec) {
						getHotelTips();
						calculateNight();
						compareDate();
					}
				});
				$("input", $("#roomNumber").next("span")).blur(function () {
					getHotelTips()
				});
				$("#hotel").combobox("setValue",data.data.hotelId);
				$("#roomType").combobox("setValue",data.data.roomType);
				$("#checkinDate").combobox("setValue",data.data.checkinDate);
				$("#checkoutDate").combobox("setValue",data.data.checkoutDate);
				$("#roomNumber").numberbox("setValue",1);
				$("#roomNumber").numberbox({ disabled: true });
				$("#checkInNumber").numberbox("setValue",parseInt(data.data.checkinNumber));
				$("span[id='roomPrice']").html(data.data.currency + " " + data.data.price);

				$("#contactName").textbox("setValue",data.data.contact);
				$("#contactMobile").textbox("setValue",data.data.contactPhone);
				$("#contactMail").textbox("setValue",data.data.contactMail);
				$("#hotelRemark").textbox("setValue",data.data.remark);

				getHotelTipsForEdit(data.data.name1,data.data.name2,loading,data.data.isCombine);
				calculateNight();

				$("#hotelBookingWindow").panel({title: "@Resources.Modify"+"@Resources.HotelBooking"});
				$("#hotelBookingWindow").window("open");
			}
		});
	}

	function getHotelTipsForEdit(name1, name2, loading, isCombine, profileId) {
		var roomId = $("#roomType").combobox("getValue");
		var checkinDate = $("#checkinDate").combobox("getValue");
		var checkoutDate = $("#checkoutDate").combobox("getValue");
		var roomNumber = $("#roomNumber").numberbox("getValue");
		var hotelId = $("#hotel").combobox("getValue");
		var currency = $("#hidCurrency").val();

		if (roomId != "" && checkinDate != "" && checkoutDate != "" && roomNumber != "" && checkinDate <= checkoutDate) {
			var url = "@Url.Action(nameof(MeetingBookingController.GetHotelTips),
			nameof(MeetingBookingController).GetControllerName())" + "?roomId=" + roomId
					+ "&checkinDate=" + checkinDate + "&checkoutDate=" + checkoutDate + "&roomNumber=" + roomNumber + "&hotelId=" + hotelId
					+ "&currency=" + currency +"&conferenceId=" + $("#hidConferenceId").val() + "&profileHotelId=" + $("#profileHotelId").val();
			$.post(url, null, function (data, textStatus, jqXHR) {
				$("span[id='leftRoomName']").html(data.data.roomType)
				$("span[id='leftRoomCount']").html(data.data.leftRoomCount)
				var dateList = data.data.checkinDateList;
				var couldList = data.data.couldBookList;
				$("#leftRoomDetail").empty();
				var appendText = "<div style='margin-top: 5px;display:inline-block;'>"
				for (var i = 0; i < dateList.length; i++) {
					if (couldList[i] == true) {
						appendText += "<div style='width:75px;float:left'><span style='width:40px;height:22px;line-height:22px;border-radius:4px;background:#CC353D;display:inline-block;color:#fff'>" + dateList[i] + "</span></div>"
					} else {
						appendText += "<div style='width:75px;float:left'><span style='color:#CBCBCB'>" + dateList[i] + "</span></div>"
					}
				}
				appendText += "</div>"
				$("#leftRoomDetail").append(appendText);
				document.getElementById("tips").style.display = "";

				var number = parseInt(roomNumber);
				var nameDivCount = document.getElementsByName("nameInput").length / 2; //获取现在又多少个nameDiv
				if (nameDivCount == 0) {
					$("#nameTd").append("<div style='margin-top:20px;' id='nameDiv0'>"
						+ "<span>@Resources.Room：</span>"
						+ "<span style='margin-left:10px'><input id='name_0_1" + "' name='nameInput' style='width:150px;height:27px' class='easyui-textbox' data-options='required:true'></span>"
						+ "<span style='margin-left:10px'><input  id='name_0_2" + "' name='nameInput' style='width:150px;height:27px;margin-left:5px' class='easyui-textbox' data-options='required:false'></span>"
						+"</div>");

					$("#name_0_1").textbox({ });
					$("#name_0_2").textbox({ });

					$("#nameTd").append("<div style='margin-top:7px;margin-bottom:40px' id='needCombineDiv'>"
							+"<input id='needCombine' type='checkbox' style='position:relative;top:7px;'>"
							+"<span id='combineText'>@Resources.NeedCombine</span>"
						+ "</div>");

					if (data.data.roomBedCount == "1") {
						$("#needCombine").hide()
						$("span[id='combineText']").html("");
					}
					if (isCombine == true) {
						$("#needCombine").prop("checked",true)
					} else {
						$("#needCombine").prop("checked",false)
					}
					$("#name_0_1").textbox("setValue",name1);
					$("#name_0_2").textbox("setValue",name2);
				}

				if (data.data.roomBedCount == "1") {
					$("#needCombine").hide()
					$("span[id='combineText']").html("");
				}

				if (data.result == "@ConstValues.AjaxFailResult") {
					common.showError(data.message);
				}
			});
		} else if (roomId != "" && checkinDate != "" && checkoutDate != "" && roomNumber != "" && checkinDate > checkoutDate) {
			common.showError("@Resources.MsgChooseRightDate");
			document.getElementById("tips").style.display = "none";

		}
		layer.close(loading);
	}

	function calculateNight() {
		var checkinDate = $("#checkinDate").combobox("getValue");
		var checkoutDate = $("#checkoutDate").combobox("getValue");
		if (checkinDate != "" && checkoutDate != "") {
			if (checkoutDate > checkinDate) {
				var day1 = new Date(checkinDate);
				var day2 = new Date(checkoutDate);
				var count = ((day2 - day1) / (1000 * 60 * 60 * 24)).toString() ;
				$("span[id='totalNightCount']").html(count + "@Resources.Night")
			} else {
				$("span[id='totalNightCount']").html("")
			}
		}
	}

	function getHotelTips() {
		var roomId = $("#roomType").combobox("getValue");
		var checkinDate = $("#checkinDate").combobox("getValue");
		var checkoutDate = $("#checkoutDate").combobox("getValue");
		var roomNumber = $("#roomNumber").numberbox("getValue");
		var hotelId = $("#hotel").combobox("getValue");
		var currency = $("#hidCurrency").val();

		if (roomId != "" && checkinDate != "" && checkoutDate != "" && roomNumber != "" && checkinDate <= checkoutDate) {
			var url = "@Url.Action(nameof(MeetingBookingController.GetHotelTips),
			nameof(MeetingBookingController).GetControllerName())" + "?roomId=" + roomId
					+ "&checkinDate=" + checkinDate + "&checkoutDate=" + checkoutDate + "&roomNumber=" + roomNumber + "&hotelId=" + hotelId
					+ "&currency=" + currency +"&conferenceId=" + $("#hidConferenceId").val() + "&profileHotelId=" + $("#profileHotelId").val();
			$.post(url, $("#hotelForm").serialize(), function (data, textStatus, jqXHR) {
				$("span[id='leftRoomName']").html(data.data.roomType)
				$("span[id='leftRoomCount']").html(data.data.leftRoomCount)
				var dateList = data.data.checkinDateList;
				var couldList = data.data.couldBookList;
				$("#leftRoomDetail").empty();
				var appendText = "<div style='margin-top:5px;display:inline-block;'>"
				for (var i = 0; i < dateList.length; i++) {
					if (couldList[i] == true) {
						appendText += "<div style='width:75px;float:left'><span style='width:40px;height:22px;line-height:22px;border-radius:4px;background:#CC353D;display:inline-block;color:#fff'>" + dateList[i] + "</span></div>"
					} else {
						appendText += "<div style='width:75px;float:left'><span style='color:#CBCBCB'>" + dateList[i] + "</span></div>"
					}
				}
				appendText += "</div>"
				$("#leftRoomDetail").append(appendText);
				document.getElementById("tips").style.display = "";

				var number = parseInt(roomNumber);
				var nameDivCount = document.getElementsByName("nameInput").length / 2; //获取现在又多少个nameDiv
				//$("#nameTd").empty();
				if (nameDivCount < number) {
					for(var i = nameDivCount; i < number; i++){
						var tempNum = (i+1).toString();
						$("#nameTd").append("<div style='margin-top:20px;' id='nameDiv" + i.toString() + "'>"
							+ "<span>@Resources.Room" + tempNum + "：</span>"
							+ "<span style='margin-left:10px'><input id='name_" + i.toString() + "_1" + "'  name='nameInput' style='width:150px;height:27px' class='easyui-textbox' data-options='required:true'></span>"
							+ "<span style='margin-left:10px'><input  id='name_" + i.toString() + "_2" + "' name='nameInput' style='width:150px;height:27px;margin-left:5px' class='easyui-textbox' data-options='required:false'></span>"
							+"</div>");

						$("#name_" + i.toString() + "_1").textbox({ });
						$("#name_" + i.toString() + "_2").textbox({ });
					}
				} else if (number < nameDivCount) {
					for (var i = number; i < nameDivCount; i++) {
						$("#nameDiv" + i.toString()).remove();
					}
				}

				var tempFlag = $("#needCombine").is(":checked"); //获取原先是否拼房
				$("#needCombineDiv").remove()
				$("#nameTd").append("<div style='margin-top:7px;margin-bottom:40px' id='needCombineDiv'>"
						+"<input id='needCombine' type='checkbox' style='position:relative;top:7px;'>"
						+"<span id='combineText'>@Resources.NeedCombine</span>"
						+ "</div>");
				if (tempFlag) {
					$("#needCombine").attr("checked","checked");
				}

				if (data.data.roomBedCount == "1") {
					$("#needCombine").hide()
					$("span[id='combineText']").html("");
				}
				if (data.result == "@ConstValues.AjaxFailResult") {
					common.showError(data.message);
				}
			});
		} else if (roomId != "" && checkinDate != "" && checkoutDate != "" && roomNumber != "" && checkinDate > checkoutDate) {
			common.showError("@Resources.MsgChooseRightDate");
			document.getElementById("tips").style.display = "none";
		}
	}

	function doHotelBooking() {
		var isValid = $("#hotelForm").form("validate");
		if (isValid && $("#name_0_1").textbox("getValue") != "") {
			var roomNumber = $("#roomNumber").numberbox("getValue");
			var checkInNumber = $("#checkInNumber").numberbox("getValue");
			if (parseInt(checkInNumber) > parseInt(roomNumber) * 2) {
				common.showError("@Resources.MsgTooMuchCheckin");
				return;
			}
			var totalList = [];
			var hotalMap = {};
			var nameList = [];
			var fillText = 0;
			for (var j = 0; j < parseInt(roomNumber) ; j++) {
				var list = [];
				list.push($("#name_" + j + "_1").textbox("getValue"));
				list.push($("#name_" + j + "_2").textbox("getValue"));
				nameList.push(list)
				if ($("#name_" + j + "_1").textbox("getValue") != "") {
					fillText += 1;
				}
				if ($("#name_" + j + "_2").textbox("getValue") != "") {
					fillText += 1;
				}
			}
			if (fillText != checkInNumber) {
				common.showError("@Resources.MsgEqualNumber");
				return;
			}
			hotalMap.nameList = nameList;
			hotalMap.hotelId = $("#hotel").combobox("getValue");
			hotalMap.roomTypeId = $("#roomType").combobox("getValue");
			hotalMap.checkinDate = $("#checkinDate").combobox("getValue");
			hotalMap.checkoutDate = $("#checkoutDate").combobox("getValue");

			if ($("#checkinDate").combobox("getValue") >= $("#checkoutDate").combobox("getValue")) {
				common.showError("@Resources.MsgChooseRightDate");
				return;
			}
			hotalMap.roomNumber = roomNumber;
			hotalMap.checkinNumber = checkInNumber;
			hotalMap.needCombine = document.getElementById("needCombine").checked
			hotalMap.currency = $("#hidCurrency").val();
			hotalMap.conferenceId = $("#hidConferenceId").val();
			hotalMap.contactName = $("#contactName").textbox("getValue");
			hotalMap.contactMail = $("#contactMail").textbox("getValue");
			hotalMap.contactMobile = $("#contactMobile").numberbox("getValue");
			hotalMap.remark = $("#hotelRemark").textbox("getValue");
			totalList.push(hotalMap);

			var loading = layer.load(0, {
				shade: [0.4, "#fff"]
			});
			var token = $("#hotelForm").find("input[name='__RequestVerificationToken']").eq(0).val();
			var model = {};
			model.totalList = totalList;
			model.conferenceId = $("#hidConferenceId").val();
			model.orderNumber = $("#hidOrderNumber").val();

			switch ($("#hdnSubmitType").val())
			{
				case "add":

				case "edit":
					model.profileHotelId = $("#profileHotelId").val();
					$.post("@Url.Action(nameof(ConferenceCheckInController.EditHotel),
					nameof(ConferenceCheckInController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
						{
							"__RequestVerificationToken": token,
							"model": model,
						},
						function(data, textStatus, jqXHR) {
							layer.close(loading);
							if (data.result == "@ConstValues.AjaxFailResult") {
								common.showError(data.message);
							} else {
								common.showSuccess(data.message, true);
								$("#dataGrid").datagrid("reload");
								$("#hotelBookingWindow").window("close");
							}
						}
					);
					break;
			}
		}
	}

	function cancelData(id) {
		var confirmMessage = "@Resources.CfmCancelBook";
		$.messager.confirm("@Resources.Cancel", confirmMessage, function (r) {
			if (r) {
				$("#profileHotelId").val(id);
				$.post("@Url.Action(nameof(ConferenceCheckInController.CancelBooking),
				nameof(ConferenceCheckInController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#hotelForm").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid").datagrid("reload");
						}
					}
				);
			}
		});
	};

	//删除酒店预定
	function deleteData(id) {
		var confirmMessage = "@Resources.CfmDeleteBook";
		$.messager.confirm("@Resources.Delete", confirmMessage, function (r) {
			if (r) {
				$("#profileHotelId").val(id);
				$.post("@Url.Action(nameof(ConferenceCheckInController.DeleteBooking),
				nameof(ConferenceCheckInController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
					$("#hotelForm").serialize(),
					function(data, textStatus, jqXHR) {
						if (data.result == "@ConstValues.AjaxFailResult") {
							common.showError(data.message);
						} else {
							common.showSuccess(data.message, true);
							$("#dataGrid1").datagrid("reload");
							$("#dataGrid2").datagrid("reload");
						}
					}
				);
			}
		});
	}

	function bookingData(id) {
		$("#profileHotelId").val(id);
		$.post("@Url.Action(nameof(ConferenceCheckInController.SetBooking),
		nameof(ConferenceCheckInController).GetControllerName(), new { ConferenceId = Model.ConferenceId })",
			$("#hotelForm").serialize(),
			function(data, textStatus, jqXHR) {
				if (data.result == "@ConstValues.AjaxFailResult") {
					common.showError(data.message);
				} else {
					common.showSuccess(data.message, true);
					$("#dataGrid").datagrid("reload");
				}
			}
		);
	}

	function compareDate() {
		if ($("#checkinDate").combobox("getValue") != "" && $("#checkoutDate").combobox("getValue") &&  $("#checkinDate").combobox("getValue") >= $("#checkoutDate").combobox("getValue")) {
			common.showError("@Resources.MsgChooseRightDate");
			return;
		}
	}

	function compareCheckInNumber() {
		var roomNumber = $("#roomNumber").numberbox("getValue");
		var checkInNumber = $("#checkInNumber").numberbox("getValue");
		if (parseInt(checkInNumber) > parseInt(roomNumber) * 2) {
			common.showError("@Resources.MsgTooMuchCheckin");
			return;
		}
	}
</script>
}